//
//  MonsterManager.cpp
//  LitterRunner
//
//  Created by 李阳 on 15/11/23.
//
//

#include "MonsterManager.hpp"
#include "Monster.hpp"
bool MonsterManager::init(){
    bool bRet = false;
    do {
        createMonsters();
        this->scheduleUpdate();
        bRet = true;
    } while (0);
    return bRet;
}
void MonsterManager::createMonsters(){
    m_monsterArr = cocos2d::CCArray::create();
    m_monsterArr->retain();
    Monster *monster = NULL;
    CCSprite *sprite = NULL;
    for (int i = 0; i < 10; i++) {
        monster = Monster::create();
        monster->bindSprite(CCSprite::create("monster.png"));
        monster->setScale(0.3);
        monster->reset();
        this->addChild(monster);
        m_monsterArr->addObject(monster);
    }
}
void MonsterManager::update(float dt){
    CCObject *obj = NULL;
    Monster *monster = NULL;
    CCARRAY_FOREACH(m_monsterArr, obj){
        monster = (Monster *)obj;
        if (monster->isAlive()) {
            monster->setPositionX(monster->getPositionX()-4);
            if (monster->getPositionX()<0) {
                monster->hide();
            }
        }else{
            monster->show();
        }
    }
}



